package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author krystal
 * @date 2023/3/26 18:00
 */
@RestController
public class RedisController {
    //1.引入redis模板
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/set")
    public String setRedis(){
        stringRedisTemplate.opsForValue().set("username","baekhyun");
        return "redis存储成功！";
    }

    @RequestMapping("/get")
    public String getRedis(){
        String result=stringRedisTemplate.opsForValue().get("username");
        return result;
    }
}
